package com.focusai.efairy.model.request;

import com.focusai.efairy.model.base.UpLoadBaseEntity;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.PureJSONRequest;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;

import org.json.JSONException;

import java.util.List;
import java.util.Map;

/**
 * Created by luo_guangwen on 2017/9/18.
 */

public class AddDevToUserRequest extends PureJSONRequest<String> {
    private String projectUserId;
    private String efairyproject_id;
    private List<Long> devIds;

    public AddDevToUserRequest(String projectId, String projectUserId, List<Long> devIds, Response.Listener<String> listener) {
        super(UrlUtils.createUrl("/appapi/user_add_device"), listener);
        this.projectUserId = projectUserId;
        this.efairyproject_id = projectId;
        this.devIds = devIds;
    }

    @Override
    protected String parse(String result) throws ParseException {
        return result;
    }

    @Override
    public Map<String, String> getParams() throws JSONException {
        return super.getParams();
    }

    @Override
    public String getPureJSON() throws JSONException {
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("efairyuser_id", CacheManager.getUserId());
//        jsonObject.put("access_token", CacheManager.getAccessToken());
//        jsonObject.put("efairyproject_user_id", projectUserId);
//        jsonObject.put("efairyproject_id", efairyproject_id);
//        if (devIds == null)
//            devIds = new ArrayList<>();
//        jsonObject.put("efairydevice_id_list", devIds);
        UploadEntry uploadEntry = new UploadEntry();
        uploadEntry.efairyproject_user_id = projectUserId;
        uploadEntry.efairyproject_id = efairyproject_id;
        uploadEntry.efairydevice_id_list = devIds;
        return GsonHelper.getInstance().toJson(uploadEntry);
    }

    private static class UploadEntry extends UpLoadBaseEntity{
        public String efairyproject_user_id;
        public String efairyproject_id;
        public List<Long> efairydevice_id_list;
    }
}


